<?php

class FColumnInfo
{
    const DEFAULT_NOW = 'now()';
    const DEFAULT_DATE_NOW = 'date(now())';
    
    private $name;
    private $type;
    private $length;
    private $formatType;
    private $notNull;
    private $default;
    private $primaryKey;
    private $uniqueKey;
    private $comment;
    
    public function isAutoIncrement()
    {
        return substr_count($this->default, 'nextval') > 0;
    }
    
    public function getName() {
        return $this->name;
    }

    public function setName($name) {
        $this->name = $name;
    }

    public function getType() {
        return $this->type;
    }

    public function setType($type) {
        $this->type = $type;
    }

    public function getLength() {
        return $this->length;
    }

    public function setLength($length) {
        $this->length = $length;
    }

    public function getFormatType() {
        return $this->formatType;
    }

    public function setFormatType($formatType) {
        $this->formatType = $formatType;
    }

    public function getNotNull() {
        return FUtil::getBooleanValue($this->notNull);
    }

    public function setNotNull($notNull) {
        $this->notNull = $notNull;
    }

    public function getDefault() {
        return str_replace("'", '', $this->default);
    }
    
    public function getDefaultValue()
    {
        $value = '';
        
        if ( !$this->isAutoIncrement() )
        {
            $value = $this->getDefault();
            
            $valueArray = explode("::", $value);
            
            $value = $valueArray[0];
            
            if ( $value == FColumnInfo::DEFAULT_NOW )
            {
                $value = date('d/m/Y H:i:s');
            }
            
            if ( $value == FColumnInfo::DEFAULT_DATE_NOW )
            {
                $value = date('d/m/Y');
            }
        }

        return $value;
    }

    public function setDefault($default) {
        $this->default = $default;
    }

    public function getPrimaryKey() {
        return FUtil::getBooleanValue($this->primaryKey);
    }

    public function setPrimaryKey($primaryKey) {
        $this->primaryKey = $primaryKey;
    }

    public function getUniqueKey() {
        return FUtil::getBooleanValue($this->uniqueKey);
    }

    public function setUniqueKey($uniqueKey) {
        $this->uniqueKey = $uniqueKey;
    }
    
    public function getComment() {
        return $this->comment;
    }

    public function setComment($comment) {
        $this->comment = $comment;
    }
    
}

?>
